package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserReuseBean;
import com.koron.css2.clientCenter.mapper.ReuseUserMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 复用详情信息
 * 
 * @author 甄玉晴
 *
 */
public class ReuseUserQuery implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			MessageBean<UserReuseBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功",
					UserReuseBean.class);
			UserReuseBean bean = JsonUtils.objectToPojo(req.getData(), UserReuseBean.class);
			//传参不能为空
			if (bean == null || StringUtils.isEmpty(bean.getId())) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "查询失败,缺少主键", null);
			}
			// 获取复用记录信息
			ReuseUserMapper mapper = factory.getMapper(ReuseUserMapper.class);
			bean = mapper.getUserReuseInfoById(bean.getId());
			bean.setSourceFlagName(Tools.getDicNameByCodeAndValue(factory, "PIS", bean.getSourceFlag()));
			info.setData(bean);
			return info;
		} catch (Exception e) {
			logger.error("复用信息查询失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
